import request from '@/utils/request'
const projectid = sessionStorage.projectId
const projectId = sessionStorage.projectId
export function getProjectPage(pageSize, pageNo, name) {
  return request({
    url: '/project/get/page',
    method: 'post',
    qs: true,
    data: {
      pageSize,
      pageNo,
      name
    }
  })
}

export function fileList(id, sort, name) {
  return request({
    url: '/folder/child/file',
    method: 'get',
    params: { projectid, id, sort, name }
  })
}

export function getFileDetails(fileid) {
  return request({
    url: '/file/note/get',
    method: 'get',
    params: { fileid }
  })
}

export function updateHtml(fileid, editorDataHTML) {
  return request({
    url: '/file/note/update/html',
    method: 'post',
    params: { fileid },
    data: editorDataHTML,
    headers: { 'Content-Type': 'text/html' }
  })
}

export function addversionHtml(fileid, editorDataHTML, description) {
  return request({
    url: '/file/note/addversion/html',
    method: 'post',
    params: { fileid, description },
    data: editorDataHTML,
    headers: { 'Content-Type': 'text/html' }
  })
}

export function fileNodeAdd(folderId, name) {
  return request({
    url: '/file/note/add',
    method: 'post',
    data: { folderId, name, type: 0, size: 0, projectId }
  })
}

export function fileAdd(folderId, name) {
  return request({
    url: '/file/add',
    method: 'post',
    data: { folderId, name, type: 0, projectId }
  })
}

export function fileUpload(file, md5) {
  var formData = new FormData()
  formData.append('file', file)
  formData.append('chunks', 1)
  formData.append('chunk', 1)
  formData.append('size', file.size)
  formData.append('fileSize', file.size)
  formData.append('md5', md5)
  return request({
    url: '/file/upload',
    method: 'post',
    data: formData
  })
}

export function fileDelete(fileId) {
  return request({
    url: '/file/recycle/' + fileId,
    method: 'get'
  })
}

// 判断文件夹是否同名
export function fileJudge(folderId, name) {
  return request({
    url: '/file/judge',
    method: 'post',
    data: { folderId, name, projectid }
  })
}

export function fileRename(parentId, name, id) {
  return request({
    url: '/file/rename',
    method: 'post',
    data: { parentId, name, id, projectId }
  })
}

export function pictureAdd(file, fileid) {
  var formData = new FormData()
  formData.append('file', file)
  formData.append('fileid', fileid)
  return request({
    url: '/file/note/picture/add',
    method: 'post',
    data: formData
  })
}

export function getVersionList(fileid) {
  return request({
    url: '/file/version/list',
    method: 'get',
    params: { fileid }
  })
}

export function getVersionDetails(id) {
  return request({
    url: '/file/version/get/' + id,
    method: 'get',
    params: { projectId }
  })
}
export function coverVisible(id) {
  return request({
    url: '/file/version/cover/' + id,
    method: 'post',
    data: { projectId }
  })
}
export function deleteVisible(id) {
  return request({
    url: '/file/version/delete/' + id,
    method: 'get'
  })
}

export function mindMapGet(id) {
  return request({
    url: '/mindMap/get/' + id,
    method: 'get'
  })
}

export function mindMapAdd(folderId, name) {
  return request({
    url: '/mindMap/add',
    method: 'post',
    data: { folderId, name, suffix: 'json', projectId }
  })
}

export function mindMapDelete(fileId) {
  return request({
    url: '/mindMap/recycle/' + fileId,
    method: 'get'
  })
}

export function mindMapJudge(folderId, name) {
  return request({
    url: '/mindMap/judge',
    method: 'post',
    data: { folderId, name, projectid }
  })
}

export function mindMapRename(parentId, name, id) {
  return request({
    url: '/mindMap/rename',
    method: 'post',
    data: { parentId, name, id, projectId }
  })
}

export function mindMapUpdate(folderId, name, id, mindMapJson) {
  return request({
    url: '/mindMap/update',
    method: 'post',
    data: { id, folderId, name, suffix: 'json', mindMapJson, projectId }
  })
}

export function fileShare(fileid, userid) {
  return request({
    url: '/file/share',
    method: 'post',
    params: { fileid, userid }
  })
}

export function exportHtml(fileid) {
  return request({
    url: '/file/export/html',
    method: 'get',
    params: { fileid }
  })
}

export function exportWord(fileid) {
  return request({
    url: '/file/export/word',
    method: 'get',
    params: { fileid }
  })
}
// 释放编辑权限
export function cancleDdit({ fileid }) {
  return request({
    url: '/file/cancle/edit/' + fileid,
    method: 'get'
  })
}

// 申请编辑权限
export function applyDdit({ fileid }) {
  return request({
    url: '/file/apply/edit/' + fileid,
    method: 'get'
  })
}
// 排序文件夹
export function fileSort(id, beforeId, afterId) {
  return request({
    url: '/file/updateposition',
    method: 'post',
    params: { id, beforeId, afterId }
  })
}

